<!--
 * @Date         : 2020-10-28 09:42:58
 * @LastEditors  : zhangyu
 * @LastEditTime : 2020-11-04 15:50:13
 * @Description  : 
-->
<template>
	<div class="table-box">
	<div class="menu-edit">
		<el-page-header @back="goBack" content="权限组授权"></el-page-header>
		<el-form ref="form" :model="model" label-width="200px" style="padding: 30px;">
			<el-form-item label="权限节点">
				<el-tree :props="setting" node-key="node" ref="tree" :data="nodes" :check-on-click-node="true" :expand-on-click-node="false" :default-expand-all="true" show-checkbox >
				</el-tree>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="onSubmit">立即保存</el-button>
				<el-button @click="goBack">取消</el-button>
			</el-form-item>
		</el-form>
	</div>
	</div>
</template>

<script>
	export default {
		props: {
			group: String
		},
		data() {
			return {
				setting: {
					label: "title",
					children: "_sub_",
				},
				nodes: [],
				model: {
					group: 0,
					nodes: []
				}
			}
		},
		async created() {
			if (!this.group) {
				this.$message.error('权限ID不存在');
			}
			let res = await this.$http.get('group/role?group=' + this.group)
			this.nodes = res.nodes
			this.model = res.model
			this.$refs.tree.setCheckedKeys(this.model.nodes);
		},
		methods: {
			async onSubmit() {
				this.model.nodes = this.$refs.tree.getCheckedKeys()
				await this.$http.post("group/role", this.model)
				this.$message.success('操作成功')
				this.$router.go(-1)
			},
			goBack() {
				this.$router.go(-1)
			},
		},
	};
</script>

<style scoped>
	
</style>
